// pages/realnamedtl/realnamedtl.js

const app = getApp()
const pathUrl = app.globalData.pathUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proAry: ['实名认证', '发起公证', '活体检测', '签署完成'],
    agree: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var telphone = wx.getStorageSync('telphone');
    var userId = wx.getStorageSync('userId')
    var writNumber = wx.getStorageSync('writNumber')
    var caseNumber = wx.getStorageSync('caseNumber')
    that.setData({
      userId: userId,
      telphone: telphone,
      writNumber: writNumber,
      caseNumber: caseNumber
    })
    this.getGuset();
    // this.getResult();
  },
  ocrNameInput: function(e) {
    this.setData({
      ocrName: e.detail.value
    })
  },
  //ocr身份证号
  idCardInput: function(e) {
    this.setData({
      idCard: e.detail.value
    })
  },
  telphoneInput: function(e) {
    this.setData({
      telphone: e.detail.value
    })
  },
  codeInput: function(e) {
    this.setData({
      code: e.detail.value
    })
  },
  agree: function(e) {
    console.log(e.detail.value)
    if (e.detail.value == '') {
      this.setData({
        agree: false
      });
    } else {
      this.setData({
        agree: true
      });
    }
  },
  gocode: function() {
    var that = this;
    wx.showLoading({})
    var userId = that.data.userId;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/doSignWithSendCode',
      method: 'POST',
      data: data,
      success: function(res) {
        console.log(res)
        console.log(res.data.message)
        console.log(JSON.parse(res.data.message))
        var a = JSON.parse(res.data.message);
        wx.hideLoading()
        if (a.resultCode == 'E00000') {
          wx.showModal({
            title: '提示',
            content: '验证码发送成功',
            showCancel: false
          })
        } else {
          wx.showModal({
            title: '提示',
            content: '验证码发送失败',
            showCancel: false

          })
        }
      },
      fail: function(res) {}
    });
  },
  getResult: function() {
    var that = this;
    var userId = that.data.userId;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/checkSignIdentityVerify',
      method: 'POST',
      data: data,
      success: function(res) {
        console.log(res)
        that.setData({
          result: res.data.message
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function(res) {}
    });
  },
  getGuset: function() {
    var that = this;
    var telphone = that.data.telphone;
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl02/list',
      method: 'GET',
      data: {
        query12: telphone,
      },
      success: function(res) {
        console.log(res.data.result.records);
        var list = res.data.result.records;
        that.setData({
          list: list,
          orcName: list[0].query13,
          idCard: list[0].query15,
          telphone: telphone
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function(res) {}
    });
  },
  // 再试一次 
  goTry: function() {
    wx.navigateBack({
      delta: 1,
    });
  },
  btnStart() {
    var that = this;
    wx.showLoading({
      title: '跳转中',
    })
    var userId = that.data.userId;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    // var pushUrl = that.data.pushUrl;
    var appletId = 'wx489d91cb36c352bb';
    var appletPath = '/pages/index/index';
    // var appletExtraData = that.data.appletExtraData;
    // var appletEnvVersion = that.data.appletEnvVersion;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
      // pushUrl: pushUrl,
      appletId: appletId,
      appletPath: appletPath,
      // appletExtraData: appletExtraData,
      // appletEnvVersion: appletEnvVersion,
    }
    console.log('123323')
    wx.request({
      url: pathUrl + '/fxy/1/doJumpApplet',
      method: 'POST',
      data: data,
      success: function (e) {
        console.log(e)
        if (!e.data.success) {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: JSON.parse(e.data.message).resultDesc,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/index/index',
                })
              }
            },
            fail: function (res) { },
            complete: function (res) { },
          })
          return false
        }
        console.log(JSON.parse(e.data.message).resultData.appletId)
        var id = JSON.parse(e.data.message).resultData.appletId;
        var path = JSON.parse(e.data.message).resultData.appletPath;
        var sn = JSON.parse(e.data.message).resultData.sn;
        console.log(sn)
        console.log(path)
        wx.setStorageSync('sn', sn)
        wx.hideLoading();
        wx.navigateToMiniProgram({
          appId: id,
          path: path,
          // extraData: {
          //   from: ''
          // },
          envVersion: 'release',
          success(res) {
            console.log(res)
            // 打开其他小程序成功同步触发
            wx.showToast({
              title: '跳转成功'
            })
            wx.switchTab({
              url: '/',
            })
          },
          // fail:function(){
          //   wx.showModal({
          //     title: '提示',
          //     content: '跳转失败',
          //     showCancel:false,
          //   })
          // }
        })
      }
    })
    // this.setData({
    //   showHtjc: false,
    // })
  },
  btnStart1() {
    var that = this;
    wx.showLoading({
      title: '跳转中',
    })
    var userId = that.data.userId1;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    // var pushUrl = that.data.pushUrl;
    var appletId = 'wx489d91cb36c352bb';
    var appletPath = '/pages/index/index';
    // var appletExtraData = that.data.appletExtraData;
    // var appletEnvVersion = that.data.appletEnvVersion;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
      // pushUrl: pushUrl,
      appletId: appletId,
      appletPath: appletPath,
      // appletExtraData: appletExtraData,
      // appletEnvVersion: appletEnvVersion,
    }
    console.log('123323')
    wx.request({
      url: pathUrl + '/fxy/1/doAuthSign',
      method: 'POST',
      data: data,
      success: function (e) {
        console.log(e)
        if (!e.data.success) {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: JSON.parse(e.data.message).resultDesc,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/index/index',
                })
              }
            },
            fail: function (res) { },
            complete: function (res) { },
          })
          return false
        }
        console.log(JSON.parse(e.data.message).resultData.appletId)
        var id = JSON.parse(e.data.message).resultData.appletId;
        var path = JSON.parse(e.data.message).resultData.appletPath;
        var sn = JSON.parse(e.data.message).resultData.sn;
        console.log(sn)
        console.log(path)
        wx.setStorageSync('sn', sn)
        wx.hideLoading();
        wx.navigateToMiniProgram({
          appId: id,
          path: path,
          // extraData: {
          //   from: ''
          // },
          envVersion: 'release',
          success(res) {
            console.log(res)
            // 打开其他小程序成功同步触发
            wx.showToast({
              title: '跳转成功'
            })
            wx.switchTab({
              url: '/',
            })
          },
          // fail:function(){
          //   wx.showModal({
          //     title: '提示',
          //     content: '跳转失败',
          //     showCancel:false,
          //   })
          // }
        })
      }
    })
    // this.setData({
    //   showHtjc: false,
    // })
  },
  // 提交信息
  // goSub: function () {
  //   var that = this;
  //   var userId = that.data.userId;
  //   var caseNumber = that.data.caseNumber;
  //   var writNumber = that.data.writNumber;
  //   var mobCode = that.data.code;
  //   var data = {
  //     userId: userId,
  //     caseNumber: caseNumber,
  //     writNumber: writNumber,
  //     mobCode: mobCode,
  //   }
  //   console.log(data)
  //   wx.request({
  //     url: pathUrl + '/fxy/1/doSignWithVerifyCode',
  //     method: 'POST',
  //     data: data,
  //     success: function (res) {
  //       console.log(res)
  //       console.log(res.data.success)
  //       if (res.data.success){
  //         var data1 ={
  //           userId: userId,
  //           caseNumber: caseNumber,
  //           writNumber: writNumber,
  //         }
  //         wx.request({
  //           url: pathUrl + '/fxy/1/doAppletParams',
  //           method: 'POST',
  //           data: data1,
  //           success:function(e){
  //             console.log(e)
  //           }
  //         })
  //       }else{
  //         wx.showModal({
  //           title: '提示',
  //           content: '验证码错误',
  //           showCancel:false
  //         })
  //       }
  //       // wx.navigateTo({
  //       //   url: '../notificationbook/notificationbook',
  //       // })
  //       // if (res.data.success) { // 登陆成功
  //       //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
  //       //   wx.navigateTo({
  //       //     url: "/pages/index/index"
  //       //   })
  //       // } else { // 登陆失败
  //       //   wx.showToast({
  //       //     title: res.data.message,
  //       //     icon: 'fail',
  //       //     duration: 1000
  //       //   });
  //       // }
  //     },
  //     fail: function (res) { }
  //   });
  // },
  goSub: function() {
    var that = this;
    var userId = that.data.userId;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    var data1 = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
    }
    wx.request({
      url: pathUrl + '/fxy/1/doJumpApplet',
      method: 'POST',
      data: data1,
      success:function(e){
        console.log(e)
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})